package edu.fdzc.learn.service.impl;

import edu.fdzc.learn.entity.User;
import edu.fdzc.learn.mapper.UserMapper;
import edu.fdzc.learn.service.UserService;
import edu.fdzc.learn.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String username) {
//        User u = new User();
//        u.setUsername(username);
        return userMapper.findByUserName(username);
    }

    @Override
    public void register(String username, String password, String role) {
//        密码加密
        String md5String = Md5Util.getMD5String(password);
        User user = new User();
        user.setUsername(username);
        user.setPassword(md5String);
        user.setRole(role);
//        user.setCreateAt();
        userMapper.insert(user);


    }

    @Override
    public User findById(int id) {
        return userMapper.findById(id);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }
}
